import ConfigParser

class Configuration :
    _config = None
    
    email = ''
    mac = ''
    so = ''
    last_analysis_id = '0'
    last_job_id = '0'
    sequence_db_path = ''
    sequence_to_process_path = ''
            
    def __init__(self):
        self._config = ConfigParser.ConfigParser()
       
    def load(self, filename):
        FILE = open( filename,"r")
        self._config.readfp( FILE)
        
        self.email = self._config.get("user", "email")
        self.mac = self._config.get("hardware", "mac")
        self.so = self._config.get('system','so')
        self.last_analysis_id = self._config.get("analysis", "last_id")
        self.sequence_db_path = self._config.get('database','sequence_db_path')
        self.sequence_to_process_path = self._config.get('database',
        'sequence_to_process_path')        
        FILE.close()
        
    def create(self, filename):
        self.clear()
        self._add_sections()
        self._set_sections_options()
        FILE = open(filename,"w")
        self._config.write( FILE)
        FILE.close()

    def write(self, filename):
        self._set_sections_options()
        FILE = open(filename,"w")
        self._config.write( FILE)
        FILE.close()
            
    def clear(self):
        self.email = ''
        self.mac = ''
        self.so = ''
        self.last_analysis_id = '0'
        self.last_job_id = '0'
        self.sequence_db_path = ''
        self.sequence_to_process_path = ''
                
    def _add_sections(self):
        self._config.add_section('user')
        self._config.add_section('system')
        self._config.add_section('hardware')
        self._config.add_section('analysis')
        self._config.add_section('database')

    def _set_sections_options(self):
        self._config.set('user','email', self.email)
        self._config.set('system','so', self.so)
        self._config.set('hardware','mac', self.mac)
        self._config.set('analysis','last_id', self.last_analysis_id)
        self._config.set('analysis','last_job_id', self.last_job_id)
        self._config.set('database','sequence_db_path', self.sequence_db_path)
        self._config.set('database','sequence_to_process_path', 
        self.sequence_to_process_path)
